﻿using UnityEngine;

public class SphereMove : MonoBehaviour
{
    [SerializeField]
    private Vector3 direction = Vector3.forward;
    [SerializeField]
    private float offsetlength = 2f;


    private Vector3 startPosition;
    private float time = 0;
    [SerializeField]
    private float timeDis =2.5f;
    private float HaveTime = 0;
    bool left = true;
    private void Start()
    {
        startPosition = transform.localPosition;
    }

    private void Update()
    {
        HaveTime += Time.deltaTime;
        if (HaveTime >= timeDis)
        {
            HaveTime = 0f;
            if (left)
            {
                left = false;
                transform.localPosition = startPosition + direction* offsetlength;
            }
            else
            {
                left = true;
                transform.localPosition = startPosition - direction * offsetlength;
            }           
      
        }
      
    }
}